package com.rem.shiro.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rem.shiro.mapper.UserMapper;
import com.rem.shiro.pojo.User;
import com.rem.shiro.service.UserService;
import com.rem.shiro.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Rem
 * @date 2021-04-07
 */

@Transactional
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    /**
     * 用户注册
     *
     * @param user
     */
    @Override
    public void register(User user) {

        String salt = SaltUtils.getSalt(4);
        Md5Hash md5Hash = new Md5Hash(user.getPassword(), salt, 1024);
        user.setSalt(salt).setPassword(md5Hash.toHex());
        baseMapper.insert(user);

    }
}
